﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Products : System.Web.UI.Page
{
    private FileUpload fileUpload;
    private Image image;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[EClass.ESession.Admin.ToString()] == null)
        {
            Response.Redirect("Login.aspx", true);
        }
        if(Request.QueryString["action"] == null)
        {
            MultiView1.ActiveViewIndex = 0;
        }
        else if(Request.QueryString["action"] == "insert")
        {
            MultiView1.ActiveViewIndex = 1;
            FormView1.DefaultMode = FormViewMode.Insert;
        }
        else if(Request.QueryString["action"] == "edit")
        {
            MultiView1.ActiveViewIndex = 1;
            FormView1.DefaultMode = FormViewMode.Edit;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        fileUpload = FormView1.FindControl("FileUpload1") as FileUpload;
        image = FormView1.FindControl("Image5") as Image;
        if(fileUpload != null && image != null && fileUpload.HasFile)
        {
            fileUpload.SaveAs(Server.MapPath("~/Images/") + fileUpload.FileName);
            image.ImageUrl = "~/Images/" + fileUpload.FileName;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        fileUpload = FormView1.FindControl("FileUpload2") as FileUpload;
        image = FormView1.FindControl("Image7") as Image;
        if (fileUpload != null && image != null && fileUpload.HasFile)
        {
            fileUpload.SaveAs(Server.MapPath("~/Images/") + fileUpload.FileName);
            image.ImageUrl = "~/Images/" + fileUpload.FileName;
        }
    }
}
